package org.lds.message.center.admin.business.channel.controller;

import lombok.extern.slf4j.Slf4j;
import org.lds.message.center.admin.business.channel.model.request.*;
import org.lds.message.center.admin.business.channel.model.response.*;
import org.lds.message.center.admin.business.channel.service.ChannelBaseService;
import org.lds.message.center.common.model.ResultDTO;
import org.lds.message.center.common.model.db.OrderBy;
import org.lds.message.center.common.model.db.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础前端控制器
 *
 * @author lidongsheng
 * @since 2024-12-22
 */
@Slf4j
@RestController
@RequestMapping("/api/common/channel")
public class ChannelBaseController {

    @Autowired
    private ChannelBaseService channelBaseService;

    /**
     * 创建
     */
    @PostMapping("/create")
    public ResultDTO<ChannelBaseResponse> createChannel(@RequestBody @Validated ChannelBaseCreateRequest request) {
        return channelBaseService.createChannel(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<ChannelBaseBatchCreateResponse> batchCreateChannel(@RequestBody @Validated ChannelBaseBatchCreateRequest request) {
        return channelBaseService.batchCreateChannel(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<ChannelBaseDeleteResponse> deleteChannel(@RequestBody ChannelBaseDeleteRequest request) {
        return channelBaseService.deleteChannel(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<ChannelBaseBatchDeleteResponse> batchDeleteChannel(@RequestBody @Validated ChannelBaseBatchDeleteRequest request) {
        return channelBaseService.batchDeleteChannel(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<ChannelBaseResponse> updateChannel(@RequestBody @Validated ChannelBaseUpdateRequest request) {
        return channelBaseService.updateChannel(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<ChannelBaseBatchUpdateResponse> batchUpdateChannel(@RequestBody @Validated ChannelBaseBatchUpdateRequest request) {
        return channelBaseService.batchUpdateChannel(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<ChannelBaseListResponse> listChannel(@RequestBody ChannelBaseListRequest request) {
        return channelBaseService.listChannel(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<ChannelBaseListResponse> listAllChannel(@RequestBody OrderBy orderBy) {
        return channelBaseService.listAllChannel(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<ChannelBaseResponse> getChannelById(@RequestBody @Validated ChannelBaseGetByIdRequest request) {
        return channelBaseService.getChannelById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<ChannelBaseListResponse> getChannelByIds(@RequestBody @Validated ChannelBaseGetByIdsRequest request) {
        return channelBaseService.getChannelByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<ChannelBaseResponse>> listChannelPage(@RequestBody ChannelBaseListPageRequest request) {
        return channelBaseService.listChannelPage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated ChannelBaseGetByKeyRequest request) {
        return ResultDTO.success(channelBaseService.getChannelByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<ChannelBaseBatchCreateResponse> batchCreateChannelAsync(@RequestBody @Validated ChannelBaseBatchCreateRequest request) {
        return channelBaseService.batchCreateChannelAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<ChannelBaseBatchDeleteResponse> batchDeleteChannelAsync(@RequestBody @Validated ChannelBaseBatchDeleteRequest request) {
        return channelBaseService.batchDeleteChannelAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<ChannelBaseBatchUpdateResponse> batchUpdateChannelAsync(@RequestBody @Validated ChannelBaseBatchUpdateRequest request) {
        return channelBaseService.batchUpdateChannelAsync(request);
    }

}